$(document).ready(function(){
	$("input[idx]").removeClass("t");
	$("input[idx=2]").addClass("t");
	$("input[idx=2]").attr("flag", "true");
	var url=location.href;
	if(url.match(/.+?(\..+)/) != null){
		var arr_url=url.split("/");

		//$(".ser_text").val(decodeURI(arr_url[arr_url.length - 1]));
	}
	$(".btn_ser").click(function () {
	    var text_val = $(".ser_text").val();
       // alert(text_val);return;
	    /*if (text_val && text_val != "") {

	        if ($(".ser_text").val() == decodeURI(str)) {

	        } else {
	            location.href = "../error/error.aspx" + decodeURI(text_val);
	        }
	    }*/

	});
	$(".c_sec table tr:odd").addClass("active");
	var last_idx=[];
	$(".btn_ckbox").click(function(){
		$("#info_zcx").hide("fast");
		var idx=$(this).attr("idx");
	 		last_idx.push(idx);
		//当last_idx的个数小于2的时候，可以随便点击
		if(last_idx.length<=3){
			$(this).css({backgroundImage:"url(./tpl/Domain/default/static/whois/images/right.png)",backgroundPosition:"50% 50%",backgroundRepeat:"no-repeat"});
	 		$(this).attr("flg",true);
	 		var num=$(".btn_ckbox[flg=true]").length;
	 		// 说明重复点击同一元素让它自动切换
	 		if((num<2 && last_idx.length==2) || (num<2 && last_idx.length>2)){
	 			$(this).attr("flg",false);
				$(this).css("background","#fff");
				last_idx.length=0;
	 		}
		}
	});
	// 查看历史信息
	$(".btn_ck").click(function(){
		$("#info_history").show("fast");
	});
	// 展开历史信息
	$("#cli_zk").click(function(){
		$("#info_history").hide("fast");
		var src_fi=$(this).find("img").attr("src");
		if(src_fi.indexOf("round_01")>0){
			$("#info_zcx").show("fast");
			$(this).find("img").attr("src","{pigcms{$static_path}whois/images/round_02.png");
		}else{
			$("#info_zcx").hide("fast");
			$(this).find("img").attr("src","{pigcms{$static_path}whois/images/round_01.png");
		}
	});
    //展开历史信息
	$(".btn_ck").click(function () {
	    var id = $(this).attr("ind");
	    $.ajax({

	        type: "post",
	        url: "./index.php?c=Whois&a=get_history&id="+id,
	        data: { id: id },
	        dataType: "json",
	        success: function (data) {
                //alert(data.domainName);
	            $("#history_duibi").hide("fast");
	            var html = '';
	            html += '<div id="Div1" style="display:block;"><div class="se_info_zhuce wx_953"> <a href="javascript:void(0);">'
	            + '<span class="cli_more">域名：' + data.domainName + ' - [' + ChangeDateFormat(data.update_time) + '] - 详细whois历史信息</span></a></div>'
	            + '<div class="se_info" style="display:block;"> <div class="infos"><pre>' + data.all + '</pre></div></div></div>';
	            $("#info_history").html(html);
	            $(window).scrollTop(500);
	        }, error: function (data) {
	        }
	    });
	});
});




function formatStr(str, flag) {
    var arr_status = [];
    if (str.indexOf("\n") >= 0) {
        var strs_one = str.split("\n");

       for (var i = 0, j = strs_one.length; i < j; i++) {
           if (strs_one[i] != "") {
               strs_one[i] += "(" + getState(strs_one[i]) + ")";
               arr_status.push(strs_one[i]);
           }
       }
       if (flag == 1) {
           return arr_status.join("<br/>");
       } else {
           return str.split("\n").join("<br/>");
       }
    } else {
        var strs_one = str.split(" ");

        for (var i = 0, j = strs_one.length; i < j; i++) {
            if (strs_one[i] != "") {
                strs_one[i] += "(" + getState(strs_one[i]) + ")";
                arr_status.push(strs_one[i]);
            }
        }
        if (flag == 1) {
            return arr_status.join("<br/>");
        } else {
            return str.split(" ").join("<br/>");
        }

      
    }
}

function getState(state) {
    var result = state.replace("[\r\n]+", "").toLowerCase();
    switch (result.toLowerCase()) {
        case "clientdeleteprohibited":
            result = "运营商设置了禁止删除";
            break;
        case "clienttransferprohibited":
            result = "运营商设置了禁止转移";
            break;
        case "clientupdateprohibited":
            result = "运营商设置了禁止修改";
            break;
        case "serverdeleteprohibited":
            result = "域名服务器设置了禁止删除";
            break;
        case "servertransferprohibited":
            result = "域名服务器设置了禁止转移";
            break;
        case "serverupdateprohibited":
            result = "域名服务器设置了禁止修改";
            break;
        case "serverrenewprohibited":
            result = "域名服务器设置了禁止续费";
            break;
        case "clientrenewprohibited":
            result = "运营商设置了禁止续费";
            break;
        case "ok":
            result = "正常状态";
            break;
        case "inactive":
            result = "非激活状态";
            break;
        case "pendingtransfer":
            result = "即将转移";
            break;
        case "pendingupdate":
            result = "即将更新";
            break;
        case "pendingpenew":
            result = "即将续费";
            break;
        case "pendingdelete":
            result = "即将删除";
            break;
        case "serverhold":
            result = "域名服务器留置";
            break;
        case "clienthold":
            result = "运营商留置";
            break;
        case "serverlock":
            result = "域名服务器锁定";
            break;
        case "redemptionperiod":
            result = "赎回期";
            break;
        case "pendingrestore":
            result = "即将恢复";
            break;

    }
    return result;

}

    function ChangeDateFormat(cellval)
    {


        var date = new Date(parseInt(cellval) *1000);

        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate;
    }